#define DEBUG
#include <cstdio>
#include <cstring>

using namespace std;

const int maxn=30, dir[8][2]={{-1, -1}, {-1, 1}, {1, -1}, {1, 1}, {-1, 0}, {0, -1}, {0, 1}, {1, 0}}, mods=1000000009;

int n, m;
char map[maxn+1][maxn+1];
int f[maxn+1][maxn+1][maxn+1][maxn+1], tr[8][4];
bool book[maxn+1][maxn+1][maxn+1][maxn+1];

inline bool check(int d, int td) {
  int p=dir[d][0], q=dir[d][1];
  return td<4 ? (p*dir[td][0]>=0 && q*dir[td][1]>=0) : d==td;
}

int solve(int x, int y, int p, int u, int v, int q) {
  if (book[x][y][u][v]) return f[x][y][u][v];
  else if (map[x][y]!=map[u][v]) {
    f[x][y][u][v] = 0;
    book[x][y][u][v] = true;
    return 0;
  }

  for (int i=1; i<=tr[p][0]; i++) {
    int nx=x+dir[tr[p][i]][0], ny=y+dir[tr[p][i]][1];
    if (nx>0 && ny>0 && nx<=n && ny<=m) {
      for (int j=1; j<=tr[q][0]; j++) {
        int nu=u+dir[tr[q][j]][0], nv=v+dir[tr[q][j]][1];
        if (nu>0 && nv>0 && nu<=n && nv<=m) {
          if (map[nx][ny]==map[nu][nv]) {
            f[x][y][u][v] = (f[x][y][u][v]+1+solve(nx, ny, p, nu, nv, q))%mods;
          }
        }
      }
    }
  }
  book[x][y][u][v] = true;
  return f[x][y][u][v];
}

int main() {
  freopen("makina.in", "r", stdin);
  freopen("makina.out", "w", stdout);

  scanf("%d %d", &n, &m);
  for (int i=1; i<=n; i++) {
    for (int j=1; j<=m; j++) {
      scanf(" %c ", &map[i][j]);
    }
  }

  for (int i=0; i<8; i++) {
    for (int j=0; j<8; j++) {
      if (check(j, i)) {
        tr[i][++tr[i][0]] = j;
      }
    }
  }

  int ans=0;
  for (int i=0; i<8; i++) {
    for (int j=i; j<8; j++) {
      memset(book, 0, sizeof book);
      memset(f, 0, sizeof f);
      int t = (i<4 && j<4) || (i>=4 && j>=4) ? 1 : -1;
      if (i!=j) t=t*2;
      int temp=0;
      for (int x=1; x<=n; x++) {
        for (int y=1; y<=m; y++) {
          for (int u=1; u<=n; u++) {
            for (int v=1; v<=m; v++) {
              temp = (temp+solve(x, y, i, u, v, j))%mods;
            }
          }
        }
      }
      ans = (ans+(mods+(t*temp)%mods)%mods)%mods;
    }
  }

  printf("%d\n", ans);

  fclose(stdin);
  fclose(stdout);
  return 0;
}
